<?php

class Utilities
{
    function html2text($html)
    {
        $tags = array (
        0 => '~<h[123][^>]+>~si',
        1 => '~<h[456][^>]+>~si',
        2 => '~<table[^>]+>~si',
        3 => '~<tr[^>]+>~si',
        4 => '~<li[^>]+>~si',
        5 => '~<br[^>]+>~si',
        6 => '~<p[^>]+>~si',
        7 => '~<div[^>]+>~si',
        );
        $html = preg_replace($tags,"\n",$html);
        $html = preg_replace('~</t(d|h)>\s*<t(d|h)[^>]+>~si',' - ',$html);
        $html = preg_replace('~<[^>]+>~s','',$html);
        // reducing spaces
        $html = preg_replace('~ +~s',' ',$html);
        $html = preg_replace('~^\s+~m','',$html);
        $html = preg_replace('~\s+$~m','',$html);
        // reducing newlines
        $html = preg_replace('~\n+~s',"\n",$html);
        return $html;
    }
    
    function cookie2Array($cookieFilePath)
    {
        $cookieArray = Array();
        $buffer = file_get_contents($cookieFilePath);
        $lines = explode("\n", $buffer);
        foreach($lines as $line)
        {
            $line = trim($line);
            
            // skip comment and blank line
            if($line != "" && substr($line, 0, 1) != "#")
            {
                unset($cookie);
                $cookie = explode("\t", $line);
                
                $cookieArray[$cookie[5]] = array
                (
                    'domain' => $cookie[0],
                    'httponly' => $cookie[1],
                    'path' => $cookie[2],
                    'secure' => $cookie[3],
                    'expire' => $cookie[4],
                    'value' => $cookie[6],
                );
            }
        }
        return $cookieArray;
    }
    
   
    
}
?>